#include "bits/stdc++.h"

using namespace std;


int main(){
    int64_t n, m;
    while(cin>>n>>m){
        int64_t levelN = sqrt(n-1)+1;
        int64_t levelM = sqrt(m-1)+1;
        int64_t leftN = (n-(pow(levelN-1, 2)+1))/2;
        int64_t leftM = (m-(pow(levelM-1, 2)+1))/2;
        int64_t rightN = (pow(levelN, 2)-n)/2;
        int64_t rightM = (pow(levelM, 2)-m)/2;
        int64_t res = abs(levelM-levelN)+abs(leftM-leftN)+abs(rightM-rightN);
        cout << res << endl;
    }
    return 0;
}
